import Vue from 'vue'
import VueRouter from 'vue-router'
import Main from '@/views/Main.vue'
import Login from '@/views/Login.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/redirect',
    component: Main,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect')
      }
    ]
  },
  {
    path: '/',
    component: Login,
  },
  {
    path: '/',
    component: Main,
    redirect: '/index',
    children: [
      {
        path: '/index',
        component: () => import('@/views/MainPage/index/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    name: "shipperManager",
    path: "/shipperManager",
    hidden: false,
    component: Main,
    children: [
      {
        path: 'index',
        component: () => import('@/views/MainPage/shipperManager/index'),
        name: 'shipperManagerIndex',
        meta: { title: '货主管理', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    name: "driverCarManager",
    path: "/driverCarManager",
    hidden: false,
    component: Main,
    meta: {
      "title": "司机车辆管理",
      "icon": "system",
      "link": null
    },
    children: [
      {
        path: 'driverAuditing',
        component: () => import('@/views/MainPage/driverCarManager/driverAuditing'),
        name: 'driverAuditing',
        meta: { title: '司机审核', icon: 'dashboard', affix: true }
      },
      {
        path: 'carAuditing',
        component: () => import('@/views/MainPage/driverCarManager/carAuditing'),
        name: 'carAuditing',
        meta: { title: '车辆审核', icon: 'dashboard', affix: true }
      },
    ]
  },
  {
    name: "waybillManagement",
    path: "/waybillManagement",
    hidden: false,
    component: Main,
    meta: {
      "title": "运单管理",
      "icon": "system",
      "link": null
    },
    children: [
      {
        path: 'allList',
        component: () => import('@/views/MainPage/waybillManagement/allList'),
        name: 'allList',
        meta: { title: '总运单列表', icon: 'dashboard', affix: true }
      },
      {
        path: 'inList',
        component: () => import('@/views/MainPage/waybillManagement/inList'),
        name: 'inList',
        meta: { title: '进行中运单', icon: 'dashboard', affix: true }
      },
      {
        path: 'suspendList',
        component: () => import('@/views/MainPage/waybillManagement/suspendList'),
        name: 'suspendList',
        meta: { title: '已暂停运单', icon: 'dashboard', affix: true }
      },
      {
        path: 'trackList',
        component: () => import('@/views/MainPage/waybillManagement/trackList'),
        name: 'trackList',
        meta: { title: '分运单追踪', icon: 'dashboard', affix: true }
      },
    ]
  },
  {
    name: "moneyManagment",
    path: "/moneyManagment",
    hidden: false,
    component: Main,
    meta: {
      "title": "财务管理",
      "icon": "system",
      "link": null
    },
    children: [
      {
        path: 'auditing',
        component: () => import('@/views/MainPage/moneyManagment/auditing'),
        name: 'auditing',
        meta: { title: '财务审核', icon: 'dashboard', affix: true }
      },
      {
        path: 'collect',
        component: () => import('@/views/MainPage/moneyManagment/collect'),
        name: 'collect',
        meta: { title: '汇总代开', icon: 'dashboard', affix: true }
      },
      {
        path: 'shipperStream',
        component: () => import('@/views/MainPage/moneyManagment/shipperStream/shipperStream'),
        name: 'shipperStream',
        meta: { title: '货主流水', icon: 'dashboard', affix: true }
      },
      {
        path: 'driverStream',
        component: () => import('@/views/MainPage/moneyManagment/driverStream'),
        name: 'driverStream',
        meta: { title: '司机流水', icon: 'dashboard', affix: true }
      },
      {
        path: 'vaildate',
        component: () => import('@/views/MainPage/moneyManagment/payValidate/payValidate'),
        name: 'vaildate',
        meta: { title: '支付结果验证', icon: 'dashboard', affix: true }
      },
      {
        name: "invoiceManage",
        path: "invoiceManage",
        component: () => import('@/views/MainPage/moneyManagment/invoiceManage/invoiceManage'),
        meta: { title: '发票管理', icon: 'dashboard', affix: true }
      },
      {
        name: "invoiceDetail",
        path: "invoiceDetail",
        component: () => import('@/views/MainPage/moneyManagment/invoiceDetail/invoiceDetail'),
        meta: { title: '发票明细', icon: 'dashboard', affix: true }
      },
    ]
  },
  {
    name: "withdraw",
    path: "/withdraw",
    hidden: false,
    component: Main,
    meta: {
      "title": "提现管理",
      "icon": "system",
      "link": null
    },
    children: [
      {
        path: 'allList',
        component: () => import('@/views/MainPage/withdraw/allList'),
        name: 'allList',
        meta: { title: '提现管理', icon: 'dashboard', affix: true }
      }
    ]
  },
  // {
  //   name: "test",
  //   path: "/test",
  //   hidden: false,
  //   component: Main,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/MainPage/test/index'),
  //       name: 'test',
  //       meta: { title: '测试页面', icon: 'dashboard', affix: true }
  //     }
  //   ]
  // },
  { path: '*', redirect: '/' }
]

// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
let routerReplace = VueRouter.prototype.replace;
// push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

const router = new VueRouter({
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  routes
})

export default router
